package com.dongdong.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.dongdong.mapper.TbUserMapper;
import com.dongdong.pojo.TbUser;
import com.dongdong.pojo.TbUserExample;
import com.dongdong.service.TbUserService;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Deacription TODO
 * @Author Lenovo
 * @Date 2020/12/18 20:16
 * @Version 1.0
 **/
@Component
@Service
public class TbUserServiceImpl implements TbUserService {

    @Resource
    private TbUserMapper tbUserMapper;

    @Override
    public TbUser findUserByName(String name) {
        TbUserExample example = new TbUserExample();
        TbUserExample.Criteria criteria = example.createCriteria();
        criteria.andUsernameEqualTo(name);
        List<TbUser> tbUsers = tbUserMapper.selectByExample(example);
        return (tbUsers == null || tbUsers.size() == 0)? null: tbUsers.get(0);
    }

    @Override
    public List<TbUser> getUserName(String username) {
        return tbUserMapper.getUserName(username);
    }

    @Override
    public int insertUser(TbUser tbUser) {
        return tbUserMapper.insertSelective(tbUser);
    }

    @Override
    public int saveRegister(TbUser tbUser) {
        return tbUserMapper.insertSelective(tbUser);
    }
}

